package com.gugee.data.config;

import com.gugee.common.web.config.NamedParameterJdbcTemplate;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

@Configuration
public class DbConfig {

    /*@Bean("oldTemplate")
    public JdbcTemplate oldTemplate(@Qualifier("oldDataSource") DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }*/

    /*@Bean("oldDataSource")
    @ConfigurationProperties("spring.old")
    public DataSource oldDataSource() {
        return DataSourceBuilder.create().build();
    }*/

    /*@Bean("newTemplate")
    public JdbcTemplate newTemplate(@Qualifier("newDataSource") DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }*/

    @Bean("newDataSource")
    @ConfigurationProperties("spring.new")
    public DataSource newDataSource() {
        return DataSourceBuilder.create().build();
    }

    @Bean
    @Primary
    public NamedParameterJdbcTemplate namedParameterJdbcTemplate(DataSource newDataSource){
        return new NamedParameterJdbcTemplate(newDataSource);
    }

    /*@Bean
    @Primary
    public NamedParameterJdbcTemplate namedParameterJdbcTemplate(@Qualifier("newDataSource") DataSource newDataSource){
        return new NamedParameterJdbcTemplate(newDataSource);
    }*/





}
